	package actions;

	import java.sql.SQLException;

	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.RowSet;

	import org.apache.struts.action.*;

import db.DbException;

	//import db.DbException;
	import forms.DeleteForm;

import model.*;

	public class DeleteAction extends Action {

		public ActionForward execute(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response){

			// Cast the form
			DeleteForm iForm = (DeleteForm) form;
			String username = iForm.getUsername();
			
			
			// Delete the student
			try {
				Database.deleteReviewer(username);
			} catch (DbException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			// Retrieve all students
			
			HttpSession session = request.getSession();
			RowSet crsReviewers = (RowSet) session.getAttribute("crsReviewers");
			
			try {
				crsReviewers = Database.getAllReviewers();
			} catch (DbException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			// Store the RowSet in the request scope
			session.setAttribute("crsReviewers", crsReviewers);

			return mapping.findForward("success");
		}
	}

